﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................

namespace QLKTX1._0.DAO
{
    class TenPhongDAO
    {
        public static List<TenPhongDTO> dsTenPhong()
        {
            List<TenPhongDTO> dstenPhong = new List<TenPhongDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM tenPhong");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TenPhongDTO tp = new TenPhongDTO();

                tp.MaTenPhong = Int32.Parse(dt.Rows[i]["maTenPhong"].ToString());
                tp.SoPhong = dt.Rows[i]["soPhong"].ToString();

                dstenPhong.Add(tp);//them vao list  doi tuong TenPhong vao list
            }
            return dstenPhong;
        }

        //ham them ten phong
        public static bool themTenPhong(TenPhongDTO tenPhong)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery ("INSERT INTO tenPhong(soPhong) VALUES('"+tenPhong .SoPhong +"')") ;
        }

        //ham xoa ten phong
        public static bool xoaTenPhong(TenPhongDTO tenPhong)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("DELETE FROM tenPhong WHERE maTenPhong='"+tenPhong .MaTenPhong +"' ");
        }

        //ham cap nhat ten phong
        public static bool capNhatTenPhong(TenPhongDTO tenPhong)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("UPDATE tenPhong set soPhong='" + tenPhong.SoPhong + "' WHERE maTenPhong='"+tenPhong.MaTenPhong + "' ");
        }
    }
}
